import { createRouter, createWebHistory } from 'vue-router'
import layout_ad from "@/layout/layout_ad.vue";
import layout_tea from "@/layout/layout_tea.vue";
import layout_stu from "@/layout/layout_stu.vue";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/',
      name:'main',
      redirect:"/login"
    },
      //管理员端
    {
      path: '/administrator',
      name: 'administrator',
      component: layout_ad,
      redirect:"/administrator/teacher_ad",
      meta:{title: "首页"},
      children:[
        {
          path: '/administrator/teacher_ad',
          name: 'teacher_ad',
          component: ()=> import("@/views/administrator/teacher_ad.vue"),
          meta:{title: "教师管理"}
        },
        {
          path: '/administrator/student_ad',
          name: 'student_ad',
          component: () =>import("@/views/administrator/student_ad.vue"),
          meta:{title:"学生管理"}
        },
        {
          path: '/administrator/project_ad',
          name: 'project_ad',
          component: () =>import("@/views/administrator/project_ad.vue"),
          meta:{title: "项目组管理"}
        },
        {
          path: '/administrator/team_ad',
          name: 'team_ad',
          component: () =>import("@/views/administrator/team_ad.vue"),
          meta:{title: "团队管理"}
        },
        {
          path: '/administrator/document_up',
          name: 'document_up',
          component: () =>import("@/views/administrator/document_up.vue"),
          meta:{title: "文档上传"}
        },
      ]
    },
      //教师端
    {
      path: '/teacher',
      name: 'teacher',
      component: layout_tea,
      redirect:"/teacher/studentdy_tea",
      meta:{title: "首页"},
      children:[
        {
          path: '/teacher/studentdy_tea',
          name: 'studentdy_tea',
          component: ()=> import("@/views/teacher/studentdy_tea.vue"),
          meta:{title: "学生动态"},
        },
        {
          path: '/teacher/guidance_tea',
          name: 'guidance_tea',
          component: () =>import("@/views/teacher/guidance_tea.vue"),
          meta:{title: "交流指导"},
        },
        {
          path: '/teacher/scoring_tea',
          name: 'scoring_tea',
          component: () =>import("@/views/teacher/scoring_tea.vue"),
          meta:{title: "综合打分"},
        },
        {
          path:'/teacher/productsub_tea',
          name:'productsub_tea',
          component:() =>import ('@/views/teacher/productsub_tea.vue'),
          meta:{title: "成果物提交管理"},
        },
        {
          path:'/teacher/teamscoring_tea',
          name:'teamscoring_tea',
          component:() =>import ('@/views/teacher/teamscoring_tea.vue'),
          meta:{title: "团队打分"},
        },
        {
          path:'/teacher/person_tea',
          name:'person_tea',
          component:() =>import ('../views/teacher/person_tea.vue')
        },
      ]
    },
      //学生端
    {
      path: '/student',
      name: 'student',
      component: layout_stu,
      redirect:"/student/personal_stu",
      meta:{title: "首页"},
      children:[
        {
          path: '/student/personal_stu',
          name: 'personal_stu',
          component: ()=> import("@/views/student/personal_stu.vue"),
          meta:{title: "个人信息管理"},
        },
        {
          path: '/student/teamdy_stu',
          name: 'teamdy_stu',
          component: () =>import("@/views/student/teamdy_stu.vue"),
          meta:{title: "团队动态"},
        },
        {
          path: '/student/productsub_stu',
          name: 'productsub_stu',
          component: () =>import("@/views/student/productsub_stu.vue"),
          meta:{title: "成果物提交"},
        },
        {
          path: '/student/document_down',
          name: 'document_down',
          component: () =>import("@/views/student/document_down.vue"),
          meta:{title: "模板下载"},
        },
        {
          path: '/student/chat_stu',
          name: 'chat_stu',
          component: () =>import("@/views/student/chat_stu.vue"),
          meta:{title: "交流反馈"},
        },
        {
          path:'/student/person_stu',
          name:'person_stu',
          component:() =>import ('../views/student/person_stu.vue')
        },
      ]
    },

    {
      path: '/login',
      name: 'login',
      component:  ()=> import('../views/login.vue')
    },
  ]
})
router.beforeEach((to,from,next)=>{
  let accessToken=localStorage.getItem("accessToken")
  console.log(accessToken)
  if(accessToken||to.path==='/login'){
    next();
  }else {
    next('/login')
  }
})

export default router
